package com.yyedu.examol.util;

import java.util.Properties;

public class Configuration {
	private static Properties[] props = null;// 读取 Properties配置文件信息
	static {
		try {
			String propsRoot = "properties";	//根目录
			String propsSuffix = ".properties";	//属性文件后缀
			String[] propsName = {
				"DataBaseConfig",	"SystemConfig",
				"DaoConfig",		"TableConfig"
			};
			props = new Properties[propsName.length];
			for (int i = 0; i < propsName.length; i++) {
				props[i] = new Properties();
				props[i].load(Configuration.class.getClassLoader().getResourceAsStream(
						propsRoot + "/" + propsName[i] + propsSuffix
				));
			}	
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 根据键获得值
	 * @param key
	 * @return
	 */
	public static String get(String key) {
		for (Properties prop : props) {
			if(prop.containsKey(key)){
				return prop.getProperty(key);
			}
		}
		return null;
	}
}
